using Grpc.Net.Client;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Xunit;

namespace CodeCity.K8S.UnitTest
{
    public class UnitTest1
    {
        [Fact]
        public async System.Threading.Tasks.Task Test1Async()
        {
            var httpClientHandler = new HttpClientHandler();
            // Return `true` to allow certificates that are untrusted/invalid
            httpClientHandler.ServerCertificateCustomValidationCallback =
                HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
            var httpClient = new HttpClient(httpClientHandler);

            var channel = GrpcChannel.ForAddress("https://101.132.78.157",
                new GrpcChannelOptions { HttpClient = httpClient });
            var helper = new DockerServiceClient(channel);
            await helper.RegisterImageAsync("placeholder");
        }

        [Fact]
        public async System.Threading.Tasks.Task DeployImagesAsync()
        {
            var httpClientHandler = new HttpClientHandler();
            // Return `true` to allow certificates that are untrusted/invalid
            httpClientHandler.ServerCertificateCustomValidationCallback =
                HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
            var httpClient = new HttpClient(httpClientHandler);

            var channel = GrpcChannel.ForAddress("https://101.132.78.157",
                new GrpcChannelOptions { HttpClient = httpClient });
            var helper = new DockerServiceClient(channel);
            //await helper.RegisterImageAsync("test4" );
            //await helper.DeployImageAsync("test4", 804);
            for (int i = 1; i <= 15; i++)
            {
                await helper.RegisterImageAsync("test" + i);
                //await Task.Delay(1000);
                await helper.DeployImageAsync("test" + i, 800 + i);
                //break;
            }
        }

        //[Fact]
        //public async Task DeployImagesFromGiteeAsync()
        //{
        //    var httpClientHandler = new HttpClientHandler();
        //    // Return `true` to allow certificates that are untrusted/invalid
        //    httpClientHandler.ServerCertificateCustomValidationCallback =
        //        HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
        //    var httpClient = new HttpClient(httpClientHandler);

        //    var channel = GrpcChannel.ForAddress("https://101.132.78.157",
        //        new GrpcChannelOptions { HttpClient = httpClient });
        //    var helper = new DockerServiceClient(channel);

        //    var data =  await helper.DeployFromGiteeAsync("aspxlover", "D32E0185CF8527FE04896B2ACF4AB8BA", "166e931a323d76017a99632a028ef3db");

        //    foreach (var item in data.Menus) {
        //        Console.WriteLine(item.Title);

        //    }

        //    //await helper.DeployImageAsync("aspxlover", 10005);
        //}

    }
}
